package com.dingreading.cloud.mall.service.impl;

import com.dingreading.cloud.common.util.PageUtil;
import com.dingreading.cloud.mall.entity.CouponStaffLog;
import com.dingreading.cloud.mall.entity.table.CouponStaffLogTableDef;
import com.dingreading.cloud.mall.mapper.CouponStaffLogMapper;
import com.dingreading.cloud.mall.service.CouponStaffLogService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2023-11-22
 */
@Service
public class CouponStaffLogServiceImpl extends BaseServiceImpl<CouponStaffLogMapper, CouponStaffLog, CouponStaffLogTableDef> implements CouponStaffLogService {

    @Override
    protected CouponStaffLogTableDef getTable() {
        return CouponStaffLogTableDef.couponStaffLog;
    }

    @Override
    public Page<CouponStaffLog> pageList(PageUtil pageUtil, Long typeId, String keyword, Integer enabled) {
        QueryCondition condition = QueryCondition.createEmpty();

        QueryWrapper wrapper = QueryWrapper.create()
                .where(condition).orderBy(table.id.desc());

        return getMapper().paginate(Page.of(pageUtil.getPage(), pageUtil.getRows()), wrapper);
    }

    @Override
    public List<CouponStaffLog> getByCode(String code, Integer status) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.code.eq(code));
        if (null != status)
            condition.and(table.status.eq(status));

        QueryWrapper wrapper = QueryWrapper.create()
                .where(condition)
                .orderBy(table.id.desc());
        return getMapper().selectListByQuery(wrapper);
    }

}
